<template>
	<view class="content_view">
		<u-navbar title-color="#FFFFFF" height="48" back-icon-color="#FFFFFF" :border-bottom="false" :is-fixed="true" title="维保工单列表"></u-navbar>
		<u-tabs :list="list" :is-scroll="false" :current="current" @change="changeTab"></u-tabs>
		<uc-content :loading="loading">
			<!--维保工单列表页面-->
			<view v-if="maintenanceList.length<1" class="view-center">
				<u-empty  text="暂无维保工单信息" mode="list"></u-empty>
			</view>
			<view v-else>
				<view class="list-item" v-for="(item,index) in maintenanceList" :key="index" @click="checkItem(item)">
					<view class="list-top">
						<view class="list-left">{{item.name}}</view>
					</view>
					<view class="list-center u-line-2">
						<view>描述:{{ item.remark }}</view>
					</view>
					<view class="list-bottom">
						<view class="u-type-success">{{ item.statusStr }}</view>
					</view>
				</view>
				<u-loadmore :status="status" :icon-type="iconType" :load-text="loadText" />
			</view>
		</uc-content>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [{
					name: '待处理'
				}, {
					name: '办理中'
				}],
				current: 0,
				loading:false,
				maintenanceList: [],
				pageNum:0,
				finished:false,
				status: 'loadmore',
				iconType: 'flower',
				loadText: {
					loadmore: '轻轻上拉',
					loading: '努力加载中',
					nomore: '没有更多数据了'
				},
				url:'/api/app/workOrder/getWorkOrderPage'
			}
		},
		onPageScroll(e) {},
		onShow() {
			this.initView()
		},
		methods: {
			checkItem(item){
				uni.navigateTo({
					url:'/pages/index/workorder/maintenance/info?ucId='+item.ucId,
				})
			},
			initView() {
				this.loading=true,
				this.maintenanceList = []
				this.pageNum = 0
				this.getWorkOrderPage()
			},
			changeTab(index) {
				this.current = index
				switch (this.current) {
					case 0:
						this.url = " /api/app/workOrder/getWorkOrderPage"
						break;
					case 1:
						this.url = " /api/app/workOrder/getExamineWorkOrderPage"
						break;
					default :
					 break;
				}
				this.initView()
			},
			//获取故障工单分页信息数据
			getWorkOrderPage(){
				this.pageNum++
				let _this = this
				return new Promise((resolve, reject) => {
					_this.utils.request(this.url, {pageNum:this.pageNum,pageSize:10}, "post", "app", true).then(res => {
						_this.loading=false
						_this.maintenanceList.push(...res.data.list)
						_this.finished = (res.data.pageNum >= res.data.pages);
						if(_this.finished){
							_this.status = 'nomore';
						}
						resolve(res)
					}).catch(error => {
						_this.loading=false
						reject(error)
					})
				})
			},
			onReachBottom() {
				if(this.finished) return ;
				this.status = 'loading';
				this.getWorkOrderPage().then(res=>{
					if(this.finished) this.status = 'nomore';
					else this.status = 'loading';
				}).catch(error=>{
					this.loading=false
					this.status = 'nomore';
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "@/uview-ui/libs/css/style.components.scss";

	.list-item {
		padding: 30rpx 40rpx;
		background-color: #fff;
		border-bottom: #999999 1px solid;

		.list-top {
			@include vue-flex;
			justify-content: space-between;
			align-items: center;

			.list-left {
				font-weight: bold;
				font-size: 34rpx;
			}

			.list-right {
				font-size: 30rpx;
				line-height: 34rpx;
				color: #999999;
			}
		}

		.list-center {
			margin-top: 20rpx;
			font-size: 28rpx;
			color: #999999;
		}

		.list-bottom {
			display: flex;
			margin-top: 20rpx;
			font-size: 28rpx;
			justify-content: space-between;
			color: #999999;
		}
	}
</style>


